/**
 * Created by hsia on 2017/10/25.
 */
var parkOrgMainJs = function(targetObj){
    this.sysUtils = new kendoUtils();
    this.targetObj = targetObj;
    this.init();
    return this;
};
var build=false,print=false;
var buildTree;
parkOrgMainJs.prototype={
    init:function(){
        var bindFieldArray = this.sysUtils.getBindFieldArray(this.targetObj);
        var bindFunctionArray = [];
        this.bindBaseModels = new bindBaseModel(null,bindFieldArray,bindFunctionArray,null);
        this.sysUtils.bindDoucment(this.bindBaseModels,this.targetObj,this);
        this.loadMain(true);
    },
    loadMain:function (init) {

        if(build||init){
            $("#parkOrgTreeDiv").load('views/parkLotCenter/facilitiesManage/parkOrgTree.html',function(responseTxt,statusTxt,xhr){
                if(statusTxt=="success"){
                    //$("#titleBar").html("停车场快速配置");
                }else if(statusTxt=="error"){
                    layer.msg("Error: "+xhr.status+": "+xhr.statusText);
                }
            });
            build=false;
        }else{
            notification({ title:"操作无效", message:"已经退到底了"}, 'info');
        }
    },
    /**
     * 快速搭建
     */
    quickBuild:function(e){
        if(!build){
            $("#parkOrgTreeDiv").load('views/parkLotCenter/facilitiesManage/parkQuickBuild.html',function(responseTxt,statusTxt,xhr){
                if(statusTxt=="success"){
                    $("#titleBar").html("停车场快速配置");
                }else if(statusTxt=="error"){
                    layer.msg("Error: "+xhr.status+": "+xhr.statusText);
                }
            });
        }else{
            notification({ title:"操作无效", message:"您已经在搭建中..."}, 'info');
        }
        build=true;
    },
    printDevice:function(e){
        if(!print){
            $("#parkOrgTreeDiv").load('views/parkLotCenter/facilitiesManage/printParkDevice.html',function(responseTxt,statusTxt,xhr){
                if(statusTxt=="success"){
                    $("#titleBar").html("停车场设备清单打印");
                }else if(statusTxt=="error"){
                    layer.msg("Error: "+xhr.status+": "+xhr.statusText);
                }
            });
        }else{
            notification({ title:"操作无效", message:"您已经在打印中..."}, 'info');
        }
        print=true;
    },
    removeTreeNode:function () {//移除节点
        var nodes = buildTree.getSelectedNodes();
        if (nodes && nodes.length>0) {
            var id = nodes[0].id;
            notification({title:"确认信息", message:"确定删除选中数据？"}, 'confirm', {
                callback : function(){
                    $.ajax({
                        url : baseApiPath + "facilities/deletePark",
                        type : "post",
                        data : {"organizationCode" : id},
                        dataType : "json",
                        success : function(res) {
                            if (res != "") {
                                notification({ title:"删除成功", message:" {"+nodes[0].name+"}已删除"},'info');
                                buildTree.removeNode(nodes[0]);
                            }
                        },
                        error : function() {
                            notification({ title:"删除失败", message:"请检查联网状态"}, 'info');
                        }
                    });
                }
            });
        }else{
            notification({ title:"删除失败", message:"请先选中要删除的节点"}, 'info');
        }
    }
}